/**
 * 
 */
package com.quydat.forum.managedbeans;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import com.quydat.forum.entites.CategoryEntity;
import com.quydat.forum.entites.SubCategoryEntity;
import com.quydat.forum.entites.UserEntity;
import com.quydat.forum.interfaces.CategoryEntityManageLocal;
import com.quydat.forum.interfaces.UserEntityManageLocal;

/**
 * @author Dat Tran - Universität Mannheim
 *Oct 15, 2011
 * Description: Index managed bean
 */
public class Index {
	/** Static final Link */
	private static final String linkSubCategory="subcategory";
	
	/**Information about user, forum, date time usw... */
	private UserEntity user;
	private String date;
	
	/**Injection EntityManage */
	@EJB
	private CategoryEntityManageLocal categoryManage;
	@EJB
	private UserEntityManageLocal userManage;
	
	/** List of category which will occur in index*/
	private List<CategoryEntity> categories;
	private SubCategoryEntity selectedSubCategory;
	
	/**
	 * 
	 * @return
	 */
	public List<CategoryEntity> getCategories() {
		categories=categoryManage.getAllCategory();
		return categories;
	}
	/**
	 * 
	 * @param categories
	 */
	public void setCategories(List<CategoryEntity> categories) {
		this.categories = categories;
	}
	
	
	
	
	/**
	 * User hat not sign in, then they are guest. guest and member have different view
	 * @return
	 */
	 public UserEntity getUser() {
		return userManage.findUserbyId(1);
		 
	}
	 /**
	  * 
	  * @param user
	  */
	public void setUser(UserEntity user) {
		this.user = user;
	}
	public String getDate() {
		if(date==null)
		{
			DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	        date=dateFormat.format(new Date());
		}
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	/** Action */
	public String viewSubCategory()
	{
		return linkSubCategory;
	}
	
	
	

}
